<?php

class CompletionTime {
	
	var $startTime;
	var $endTime;
	var $classAndMethod;
	var $qosValue;
	var $logicalOperator;
	
	function __construct($identifier, $qosValue, $logicalOperator)
	{
		$this->classAndMethod = $identifier;
		$this->qosValue = $qosValue;
		$this->logicalOperator = $logicalOperator;
		$this->startTime = $this->getmicrotime();
	}

	function getmicrotime()
	{
	    list($u, $s) = explode(' ',microtime());
	    return bcadd($u, $s, 8);
	}
	
	function __destruct()
	{
		$this->endTime = $this->getmicrotime();
		$completionTime = $this->endTime - $this->startTime;
		if($this->logicalOperator == '>' && $completionTime > $this->qosValue)
		{
			$db = new ezSQL_mysql(USERNAME, PASSWORD, DATABASE, HOSTNAME);
			$db->query("INSERT INTO completion_time (method, microtime_start, microtime_end) 
						   VALUES ('$this->classAndMethod', '$this->startTime', '$this->endTime')");
		} elseif($this->logicalOperator == '>' && $completionTime > $this->qosValue){
			$db = new ezSQL_mysql(USERNAME, PASSWORD, DATABASE, HOSTNAME);
			$db->query("INSERT INTO completion_time (method, microtime_start, microtime_end) 
						   VALUES ('$this->classAndMethod', '$this->startTime', '$this->endTime')");
		}
		
	}

}

//EOF CompletionTime.php
